package com.salmon.study.life;

import akka.actor.AbstractActor;
import akka.actor.Props;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class StartStopActor1 extends AbstractActor {

    @Override
    public void preStart() {
        System.out.println("first started");
        getContext().actorOf(Props.create(StartStopActor2.class), "second");
    }

    @Override
    public void postStop() {
        System.out.println("first stopped");
    }

    @Override
    public Receive createReceive() {
        log.info("first create Receive");
        return receiveBuilder().matchEquals("stop", s -> {
            log.info("调用");
            getContext().stop(self());
        }).build();
    }
}
